<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Glossary &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="_static/css/spc-extend.css">
    <link rel="stylesheet" href="_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    './',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <script type="text/javascript" src="_static/language_data.js"></script>
    <script type="text/javascript" src="_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="about.html" >
    <link rel="index" title="Index" href="genindex.html" >
    <link rel="search" title="Search" href="search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="index.html" >
    <link rel="prev" title="NumPy License" href="license.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="index.html">
      <img border=0 alt="NumPy" src="_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="index.html">NumPy v1.18 Manual</a></li>
        
 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="license.html" title="NumPy License"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="license.html"
                        title="previous chapter">NumPy License</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <div class="section" id="glossary">
<h1>Glossary<a class="headerlink" href="#glossary" title="Permalink to this headline">¶</a></h1>
<div class="toctree-wrapper compound">
</div>
<span class="target" id="module-numpy.doc.glossary"></span><dl class="glossary">
<dt id="term-along-an-axis">along an axis</dt><dd><p>Axes are defined for arrays with more than one dimension.  A
2-dimensional array has two corresponding axes: the first running
vertically downwards across rows (axis 0), and the second running
horizontally across columns (axis 1).</p>
<p>Many operations can take place along one of these axes.  For example,
we can sum each row of an array, in which case we operate along
columns, or axis 1:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">12</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">))</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([[ 0,  1,  2,  3],</span>
<span class="go">       [ 4,  5,  6,  7],</span>
<span class="go">       [ 8,  9, 10, 11]])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">array([ 6, 22, 38])</span>
</pre></div>
</div>
</dd>
<dt id="term-array">array</dt><dd><p>A homogeneous container of numerical elements.  Each element in the
array occupies a fixed amount of memory (hence homogeneous), and
can be a numerical element of a single type (such as float, int
or complex) or a combination (such as <code class="docutils literal notranslate"><span class="pre">(float,</span> <span class="pre">int,</span> <span class="pre">float)</span></code>).  Each
array has an associated data-type (or <code class="docutils literal notranslate"><span class="pre">dtype</span></code>), which describes
the numerical type of its elements:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span> <span class="nb">float</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([ 1.,  2.,  3.])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">dtype</span> <span class="c1"># floating point number, 64 bits of memory per element</span>
<span class="go">dtype(&#39;float64&#39;)</span>


<span class="go"># More complicated data type: each array element is a combination of</span>
<span class="go"># and integer and a floating point number</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">),</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mf">4.0</span><span class="p">)],</span> <span class="n">dtype</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="nb">float</span><span class="p">)])</span>
<span class="go">array([(1, 2.0), (3, 4.0)],</span>
<span class="go">      dtype=[(&#39;x&#39;, &#39;&lt;i4&#39;), (&#39;y&#39;, &#39;&lt;f8&#39;)])</span>
</pre></div>
</div>
<p>Fast element-wise operations, called a <a class="reference internal" href="#term-ufunc"><span class="xref std std-term">ufunc</span></a>, operate on arrays.</p>
</dd>
<dt id="term-array-like">array_like</dt><dd><p>Any sequence that can be interpreted as an ndarray.  This includes
nested lists, tuples, scalars and existing arrays.</p>
</dd>
<dt id="term-attribute">attribute</dt><dd><p>A property of an object that can be accessed using <code class="docutils literal notranslate"><span class="pre">obj.attribute</span></code>,
e.g., <code class="docutils literal notranslate"><span class="pre">shape</span></code> is an attribute of an array:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">shape</span>
<span class="go">(3,)</span>
</pre></div>
</div>
</dd>
<dt id="term-big-endian">big-endian</dt><dd><p>When storing a multi-byte value in memory as a sequence of bytes, the
sequence addresses/sends/stores the most significant byte first (lowest
address) and the least significant byte last (highest address). Common in
micro-processors and used for transmission of data over network protocols.</p>
</dd>
<dt id="term-blas">BLAS</dt><dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms">Basic Linear Algebra Subprograms</a></p>
</dd>
<dt id="term-broadcast">broadcast</dt><dd><p>NumPy can do operations on arrays whose shapes are mismatched:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">3</span><span class="p">],</span> <span class="p">[</span><span class="mi">4</span><span class="p">]])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([1, 2])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span>
<span class="go">array([[3],</span>
<span class="go">       [4]])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">+</span> <span class="n">y</span>
<span class="go">array([[4, 5],</span>
<span class="go">       [5, 6]])</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="user/basics.broadcasting.html#module-numpy.doc.broadcasting" title="numpy.doc.broadcasting"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.doc.broadcasting</span></code></a> for more information.</p>
</dd>
<dt id="term-c-order">C order</dt><dd><p>See <em class="xref py py-obj">row-major</em></p>
</dd>
<dt id="term-column-major">column-major</dt><dd><p>A way to represent items in a N-dimensional array in the 1-dimensional
computer memory. In column-major order, the leftmost index “varies the
fastest”: for example the array:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
 <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]]</span>
</pre></div>
</div>
<p>is represented in the column-major order as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">6</span><span class="p">]</span>
</pre></div>
</div>
<p>Column-major order is also known as the Fortran order, as the Fortran
programming language uses it.</p>
</dd>
<dt id="term-decorator">decorator</dt><dd><p>An operator that transforms a function.  For example, a <code class="docutils literal notranslate"><span class="pre">log</span></code>
decorator may be defined to print debugging information upon
function execution:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">log</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">new_logging_func</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="gp">... </span>        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Logging call with parameters:&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
<span class="gp">... </span>        <span class="k">return</span> <span class="n">f</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">new_logging_func</span>
</pre></div>
</div>
<p>Now, when we define a function, we can “decorate” it using <code class="docutils literal notranslate"><span class="pre">log</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="nd">@log</span>
<span class="gp">... </span><span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="n">a</span> <span class="o">+</span> <span class="n">b</span>
</pre></div>
</div>
<p>Calling <code class="docutils literal notranslate"><span class="pre">add</span></code> then yields:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">add</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="go">Logging call with parameters: (1, 2) {}</span>
<span class="go">3</span>
</pre></div>
</div>
</dd>
<dt id="term-dictionary">dictionary</dt><dd><p>Resembling a language dictionary, which provides a mapping between
words and descriptions thereof, a Python dictionary is a mapping
between two objects:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">{</span><span class="mi">1</span><span class="p">:</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="s1">&#39;two&#39;</span><span class="p">:</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]}</span>
</pre></div>
</div>
<p>Here, <em class="xref py py-obj">x</em> is a dictionary mapping keys to values, in this case
the integer 1 to the string “one”, and the string “two” to
the list <code class="docutils literal notranslate"><span class="pre">[1,</span> <span class="pre">2]</span></code>.  The values may be accessed using their
corresponding keys:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="go">&#39;one&#39;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="s1">&#39;two&#39;</span><span class="p">]</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
<p>Note that dictionaries are not stored in any specific order.  Also,
most mutable (see <em>immutable</em> below) objects, such as lists, may not
be used as keys.</p>
<p>For more information on dictionaries, read the
<a class="reference external" href="https://docs.python.org/tutorial/">Python tutorial</a>.</p>
</dd>
<dt id="term-field">field</dt><dd><p>In a <a class="reference internal" href="#term-structured-data-type"><span class="xref std std-term">structured data type</span></a>, each sub-type is called a <em class="xref py py-obj">field</em>.
The <em class="xref py py-obj">field</em> has a name (a string), a type (any valid dtype, and
an optional <em class="xref py py-obj">title</em>. See <a class="reference internal" href="reference/arrays.dtypes.html#arrays-dtypes"><span class="std std-ref">Data type objects (dtype)</span></a></p>
</dd>
<dt id="term-fortran-order">Fortran order</dt><dd><p>See <em class="xref py py-obj">column-major</em></p>
</dd>
<dt id="term-flattened">flattened</dt><dd><p>Collapsed to a one-dimensional array. See <a class="reference internal" href="reference/generated/numpy.ndarray.flatten.html#numpy.ndarray.flatten" title="numpy.ndarray.flatten"><code class="xref py py-obj docutils literal notranslate"><span class="pre">numpy.ndarray.flatten</span></code></a>
for details.</p>
</dd>
<dt id="term-homogenous">homogenous</dt><dd><p>Describes a block of memory comprised of blocks, each block comprised of 
items and of the same size, and blocks are interpreted in exactly the
same way. In the simplest case each block contains a single item, for
instance int32 or float64.</p>
</dd>
<dt id="term-immutable">immutable</dt><dd><p>An object that cannot be modified after execution is called
immutable.  Two common examples are strings and tuples.</p>
</dd>
<dt id="term-instance">instance</dt><dd><p>A class definition gives the blueprint for constructing an object:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">House</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">wall_colour</span> <span class="o">=</span> <span class="s1">&#39;white&#39;</span>
</pre></div>
</div>
<p>Yet, we have to <em>build</em> a house before it exists:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">h</span> <span class="o">=</span> <span class="n">House</span><span class="p">()</span> <span class="c1"># build a house</span>
</pre></div>
</div>
<p>Now, <code class="docutils literal notranslate"><span class="pre">h</span></code> is called a <code class="docutils literal notranslate"><span class="pre">House</span></code> instance.  An instance is therefore
a specific realisation of a class.</p>
</dd>
<dt id="term-iterable">iterable</dt><dd><p>A sequence that allows “walking” (iterating) over items, typically
using a loop such as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="p">[</span><span class="n">item</span><span class="o">**</span><span class="mi">2</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">x</span><span class="p">]</span>
<span class="go">[1, 4, 9]</span>
</pre></div>
</div>
<dl>
<dt>It is often used in combination with <code class="docutils literal notranslate"><span class="pre">enumerate</span></code>::</dt><dd><div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">keys</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span><span class="s1">&#39;b&#39;</span><span class="p">,</span><span class="s1">&#39;c&#39;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="k">for</span> <span class="n">n</span><span class="p">,</span> <span class="n">k</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">keys</span><span class="p">):</span>
<span class="gp">... </span>    <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Key </span><span class="si">%d</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">))</span>
<span class="gp">...</span>
<span class="go">Key 0: a</span>
<span class="go">Key 1: b</span>
<span class="go">Key 2: c</span>
</pre></div>
</div>
</dd>
</dl>
</dd>
<dt id="term-itemsize">itemsize</dt><dd><p>The size of the dtype element in bytes.</p>
</dd>
<dt id="term-list">list</dt><dd><p>A Python container that can hold any number of objects or items.
The items do not have to be of the same type, and can even be
lists themselves:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">,</span> <span class="s2">&quot;two&quot;</span><span class="p">,</span> <span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">]]</span>
</pre></div>
</div>
<p>The list <em class="xref py py-obj">x</em> contains 4 items, each which can be accessed individually:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># the string &#39;two&#39;</span>
<span class="go">&#39;two&#39;</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="c1"># a list, containing an integer 2 and a float 2.0</span>
<span class="go">[2, 2.0]</span>
</pre></div>
</div>
<p>It is also possible to select more than one item at a time,
using <em>slicing</em>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># or, equivalently, x[:2]</span>
<span class="go">[2, 2.0]</span>
</pre></div>
</div>
<p>In code, arrays are often conveniently expressed as nested lists:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="go">array([[1, 2],</span>
<span class="go">       [3, 4]])</span>
</pre></div>
</div>
<p>For more information, read the section on lists in the <a class="reference external" href="https://docs.python.org/tutorial/">Python
tutorial</a>.  For a mapping
type (key-value), see <em>dictionary</em>.</p>
</dd>
<dt id="term-little-endian">little-endian</dt><dd><p>When storing a multi-byte value in memory as a sequence of bytes, the
sequence addresses/sends/stores the least significant byte first (lowest
address) and the most significant byte last (highest address). Common in
x86 processors.</p>
</dd>
<dt id="term-mask">mask</dt><dd><p>A boolean array, used to select only certain elements for an operation:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([0, 1, 2, 3, 4])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">mask</span> <span class="o">=</span> <span class="p">(</span><span class="n">x</span> <span class="o">&gt;</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">mask</span>
<span class="go">array([False, False, False, True,  True])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="n">mask</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([ 0,  1,  2,  -1, -1])</span>
</pre></div>
</div>
</dd>
<dt id="term-masked-array">masked array</dt><dd><p>Array that suppressed values indicated by a mask:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ma</span><span class="o">.</span><span class="n">masked_array</span><span class="p">([</span><span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">nan</span><span class="p">],</span> <span class="p">[</span><span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">,</span> <span class="kc">True</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">masked_array(data = [-- 2.0 --],</span>
<span class="go">             mask = [ True False  True],</span>
<span class="go">       fill_value = 1e+20)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">+</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">]</span>
<span class="go">masked_array(data = [-- 4.0 --],</span>
<span class="go">             mask = [ True False  True],</span>
<span class="go">       fill_value = 1e+20)</span>
</pre></div>
</div>
<p>Masked arrays are often used when operating on arrays containing
missing or invalid entries.</p>
</dd>
<dt id="term-matrix">matrix</dt><dd><p>A 2-dimensional ndarray that preserves its two-dimensional nature
throughout operations.  It has certain special operations, such as <code class="docutils literal notranslate"><span class="pre">*</span></code>
(matrix multiplication) and <code class="docutils literal notranslate"><span class="pre">**</span></code> (matrix power), defined:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mat</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">matrix([[1, 2],</span>
<span class="go">        [3, 4]])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">**</span><span class="mi">2</span>
<span class="go">matrix([[ 7, 10],</span>
<span class="go">      [15, 22]])</span>
</pre></div>
</div>
</dd>
<dt id="term-method">method</dt><dd><p>A function associated with an object.  For example, each ndarray has a
method called <code class="docutils literal notranslate"><span class="pre">repeat</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="o">.</span><span class="n">repeat</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="go">array([1, 1, 2, 2, 3, 3])</span>
</pre></div>
</div>
</dd>
<dt id="term-ndarray">ndarray</dt><dd><p>See <em>array</em>.</p>
</dd>
<dt id="term-record-array">record array</dt><dd><p>An <a class="reference internal" href="#term-ndarray"><span class="xref std std-term">ndarray</span></a> with <a class="reference internal" href="#term-structured-data-type"><span class="xref std std-term">structured data type</span></a> which has been
subclassed as <code class="docutils literal notranslate"><span class="pre">np.recarray</span></code> and whose dtype is of type <code class="docutils literal notranslate"><span class="pre">np.record</span></code>,
making the fields of its data type to be accessible by attribute.</p>
</dd>
<dt id="term-reference">reference</dt><dd><p>If <code class="docutils literal notranslate"><span class="pre">a</span></code> is a reference to <code class="docutils literal notranslate"><span class="pre">b</span></code>, then <code class="docutils literal notranslate"><span class="pre">(a</span> <span class="pre">is</span> <span class="pre">b)</span> <span class="pre">==</span> <span class="pre">True</span></code>.  Therefore,
<code class="docutils literal notranslate"><span class="pre">a</span></code> and <code class="docutils literal notranslate"><span class="pre">b</span></code> are different names for the same Python object.</p>
</dd>
<dt id="term-row-major">row-major</dt><dd><p>A way to represent items in a N-dimensional array in the 1-dimensional
computer memory. In row-major order, the rightmost index “varies
the fastest”: for example the array:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">],</span>
 <span class="p">[</span><span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]]</span>
</pre></div>
</div>
<p>is represented in the row-major order as:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">]</span>
</pre></div>
</div>
<p>Row-major order is also known as the C order, as the C programming
language uses it. New NumPy arrays are by default in row-major order.</p>
</dd>
<dt id="term-self">self</dt><dd><p>Often seen in method signatures, <code class="docutils literal notranslate"><span class="pre">self</span></code> refers to the instance
of the associated class.  For example:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">class</span> <span class="nc">Paintbrush</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="gp">... </span>    <span class="n">color</span> <span class="o">=</span> <span class="s1">&#39;blue&#39;</span>
<span class="gp">...</span>
<span class="gp">... </span>    <span class="k">def</span> <span class="nf">paint</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="gp">... </span>        <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Painting the city </span><span class="si">%s</span><span class="s2">!&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">color</span><span class="p">)</span>
<span class="gp">...</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Paintbrush</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">color</span> <span class="o">=</span> <span class="s1">&#39;red&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">paint</span><span class="p">()</span> <span class="c1"># self refers to &#39;p&#39;</span>
<span class="go">Painting the city red!</span>
</pre></div>
</div>
</dd>
<dt id="term-slice">slice</dt><dd><p>Used to select only certain elements from a sequence:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">[0, 1, 2, 3, 4]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="c1"># slice from 1 to 3 (excluding 3 itself)</span>
<span class="go">[1, 2]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">5</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="c1"># slice from 1 to 5, but skipping every second element</span>
<span class="go">[1, 3]</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="c1"># slice a sequence in reverse</span>
<span class="go">[4, 3, 2, 1, 0]</span>
</pre></div>
</div>
<p>Arrays may have more than one dimension, each which can be sliced
individually:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([[1, 2],</span>
<span class="go">       [3, 4]])</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[:,</span> <span class="mi">1</span><span class="p">]</span>
<span class="go">array([2, 4])</span>
</pre></div>
</div>
</dd>
<dt id="term-structure">structure</dt><dd><p>See <a class="reference internal" href="#term-structured-data-type"><span class="xref std std-term">structured data type</span></a></p>
</dd>
<dt id="term-structured-data-type">structured data type</dt><dd><p>A data type composed of other datatypes</p>
</dd>
<dt id="term-subarray-data-type">subarray data type</dt><dd><p>A <a class="reference internal" href="#term-structured-data-type"><span class="xref std std-term">structured data type</span></a> may contain a <a class="reference internal" href="#term-ndarray"><span class="xref std std-term">ndarray</span></a> with its
own dtype and shape:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">dt</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">dtype</span><span class="p">([(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">int32</span><span class="p">),</span> <span class="p">(</span><span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">,</span> <span class="p">(</span><span class="mi">3</span><span class="p">,))])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dt</span><span class="p">)</span>
<span class="go">array([(0, [0., 0., 0.]), (0, [0., 0., 0.]), (0, [0., 0., 0.])],</span>
<span class="go">      dtype=[(&#39;a&#39;, &#39;&lt;i4&#39;), (&#39;b&#39;, &#39;&lt;f4&#39;, (3,))])</span>
</pre></div>
</div>
</dd>
<dt id="term-title">title</dt><dd><p>In addition to field names, structured array fields may have an
associated <a class="reference internal" href="user/basics.rec.html#titles"><span class="std std-ref">title</span></a> which is an alias to the name and is
commonly used for plotting.</p>
</dd>
<dt id="term-tuple">tuple</dt><dd><p>A sequence that may contain a variable number of types of any
kind.  A tuple is immutable, i.e., once constructed it cannot be
changed.  Similar to a list, it can be indexed and sliced:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;one&#39;</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">(1, &#39;one&#39;, [1, 2])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="go">1</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span>
<span class="go">(1, &#39;one&#39;)</span>
</pre></div>
</div>
<p>A useful concept is “tuple unpacking”, which allows variables to
be assigned to the contents of a tuple:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span>
</pre></div>
</div>
<p>This is often used when a function returns multiple values:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="k">def</span> <span class="nf">return_many</span><span class="p">():</span>
<span class="gp">... </span>    <span class="k">return</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;alpha&#39;</span><span class="p">,</span> <span class="kc">None</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span> <span class="o">=</span> <span class="n">return_many</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">c</span>
<span class="go">(1, &#39;alpha&#39;, None)</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">a</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">b</span>
<span class="go">&#39;alpha&#39;</span>
</pre></div>
</div>
</dd>
<dt id="term-ufunc">ufunc</dt><dd><p>Universal function.  A fast element-wise, <a class="reference internal" href="#term-vectorization"><span class="xref std std-term">vectorized</span></a> array operation.  Examples include <code class="docutils literal notranslate"><span class="pre">add</span></code>, <code class="docutils literal notranslate"><span class="pre">sin</span></code> and
<code class="docutils literal notranslate"><span class="pre">logical_or</span></code>.</p>
</dd>
<dt id="term-vectorization">vectorization</dt><dd><p>Optimizing a looping block by specialized code. In a traditional sense,
vectorization performs the same operation on multiple elements with
fixed strides between them via specialized hardware. Compilers know how
to take advantage of well-constructed loops to implement such
optimizations. NumPy uses <a class="reference internal" href="user/whatisnumpy.html#whatis-vectorization"><span class="std std-ref">vectorization</span></a>
to mean any optimization via specialized code performing the same
operations on multiple elements, typically achieving speedups by
avoiding some of the overhead in looking up and converting the elements.</p>
</dd>
<dt id="term-view">view</dt><dd><p>An array that does not own its data, but refers to another array’s
data instead.  For example, we may create a view that only shows
every second element of another array:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span>
<span class="go">array([0, 1, 2, 3, 4])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span> <span class="o">=</span> <span class="n">x</span><span class="p">[::</span><span class="mi">2</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span>
<span class="go">array([0, 2, 4])</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">3</span> <span class="c1"># changing x changes y as well, since y is a view on x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">y</span>
<span class="go">array([3, 2, 4])</span>
</pre></div>
</div>
</dd>
<dt id="term-wrapper">wrapper</dt><dd><p>Python is a high-level (highly abstracted, or English-like) language.
This abstraction comes at a price in execution speed, and sometimes
it becomes necessary to use lower level languages to do fast
computations.  A wrapper is code that provides a bridge between
high and the low level languages, allowing, e.g., Python to execute
code written in C or Fortran.</p>
<p>Examples include ctypes, SWIG and Cython (which wraps C and C++)
and f2py (which wraps Fortran).</p>
</dd>
</dl>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>